package com.shop2cn.iapi.sqdistributor.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.sqdistributor.parameter.request.SetDistributorStatusReq;
import com.shop2cn.iapi.sqdistributor.service.SetDistributorStatusCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.database.model.sqdistributor.DistributorRelation;
import com.ymttest.database.sqlwapper.sqdistributor.DistributorRelationWrapper;

public class Ts_SetDistributorStatus {
	
	//java接口
	private static SetDistributorStatusReq setDistributorStatusReq;
	private static SetDistributorStatusCall setDistributorStatusCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置分销员状态");
	}

	@Before
	public void caseUp() {
		setDistributorStatusReq = new SetDistributorStatusReq();
		setDistributorStatusCall = new SetDistributorStatusCall();	
	}
	
	@AfterClass
	public static void tearDown() {
		Logger.generateResult(setDistributorStatusCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	public void verifyDb() throws Exception {
		
		DistributorRelationWrapper distributorRelationWrapper = new DistributorRelationWrapper();
		
		DistributorRelation actualResult = distributorRelationWrapper
				.selectByPrimaryKey(setDistributorStatusReq.getId());

		Logger.verifyEquals(setDistributorStatusReq.getStatus() == null ? 0
				: setDistributorStatusReq.getStatus(), actualResult
				.getDistributor_status(), "验证Distributor_status");
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetDistributorStatus_001() {
		Logger.start(true, "分销员状态设置清退成功");
		
		try {
			
			setDistributorStatusReq.setId(7L);
			setDistributorStatusReq.setStatus(1);
			
			setDistributorStatusCall.setData(setDistributorStatusReq);
			setDistributorStatusCall.callService();
			
			Logger.verifyEquals(true, setDistributorStatusCall.getSuccess(), "验证success");
			
			verifyDb();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetDistributorStatus_002() {
		Logger.start(true, "分销员状态设置正常成功");
		
		try {
			
			setDistributorStatusReq.setId(7L);
			setDistributorStatusReq.setStatus(0);
			
			setDistributorStatusCall.setData(setDistributorStatusReq);
			setDistributorStatusCall.callService();
			
			Logger.verifyEquals(true, setDistributorStatusCall.getSuccess(), "验证success");
			
			verifyDb();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetDistributorStatus_003() {
		Logger.start(true, "id为null，分销员状态设置失败");
		
		try {
			
			//setDistributorStatusReq.setId(11111111L);
			setDistributorStatusReq.setStatus(0);
			
			setDistributorStatusCall.setData(setDistributorStatusReq);
			setDistributorStatusCall.callService();
			
			Logger.verifyEquals(false, setDistributorStatusCall.getSuccess(), "验证success");
			Logger.verifyEquals("id:must be greater than or equal to 1", setDistributorStatusCall.getMsg(), "验证resultMessage");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
